var app = angular.module('Module.organizationuser', ['gtiles.pagination','ui.bootstrap','treeControl','localytics.directives','selectTree',
                                                     'Module.importfileservice','ngFileUpload','tools','datatime.directive'])
.factory('organizationuserservice', function($http) {
	var service = {};
	
	//查询是否开启分级权限
	service.findIsAuthData = function() {
		return $http.get("../workbench/authData/findIsAuthData.json");
	}
	
	//获取树形结构
	service.initOrganizationTree = function() {
		return $http.get("../workbench/organization/findAllOrganizationTree.json");
	}
	
	//查询职级
	service.findProlevelList = function(){
		return $http.get("../workbench/gtdict/findDictList.json?dictCode=prolevel");
	}
	
	//获取岗位
	service.findPostList = function(){
		return $http.get("../workbench/orgpost/findOrgPostList.json?pageSize=-1");
	}

	
	// 翻页查询用户
	service.findList = function(params, paramsObj) {
		return $http({
			method : "post",
			url : "../workbench/orguser/findOrgUserList.json",
			data : params,
			headers:{'Content-Type': 'application/x-www-form-urlencoded'}
		}).then(function(response) {
			return {
				'header' : [],
				'rows' : response.data.data.resultList,
				'pagination' : response.data.data.pagination,
				"sort-by" : "orderNum",
				"sort-order" : "asc"
			}
		});
	}
	
	//预新增
	service.preAdd=function(){
		return $http.get("../workbench/orguser/preAdd.json");
	}
	
	//新增
	service.addOrgUser = function(params){
		return $http({
			method : "post",
			url : "../workbench/orguser/addOrgUser.json",
			data : angular4J.param(params),
			headers:{'Content-Type': 'application/x-www-form-urlencoded'}
		});
	}
	
	//更新
	service.updateOrgUser = function(params){
		return $http({
			method : "post",
			url : "../workbench/orguser/updateOrgUser.json",
			data : angular4J.param(params),
			headers:{'Content-Type': 'application/x-www-form-urlencoded'}
		});
	}
	
	//查询机构用户
	service.findOrgUser=function(orgUserId){
		return $http.get("../workbench/orguser/findOrgUser.json?id="+orgUserId);
	}
	
	//删除
	service.deleteById = function(id){
		return $http.get("../workbench/orguser/deleteOrgUserByIds.json?ids="+id);
	}
	
	//设置用户为管理员
	service.adminSetting = function(userId){
		return $http.get("../workbench/orguser/adminSetting.json?userId=" + userId);
	}
	
	//调整用户状态
	service.updateUserState = function(userId,currentState){
		return $http.get("../workbench/orguser/updateUserState.json?userIds=" + userId + "&toState="+ currentState);
	}
	//调整账户状态
	service.update = function(params){
		var url ="../workbench/account"+"/updateAccount.json";
		return $http({
			method : "post",
			url : url,
			data : $.param(params),
			headers:{'Content-Type': 'application/x-www-form-urlencoded'}
		});
	}
	
	//获取用户管理范围
	service.getAdminOrgScopeList = function(adminId){
		return $http.get("../workbench/orgscope/getAdminOrgScopeList.json?adminId=" + adminId);
	}
	
	//用户数据权限保存 
	service.addAdminOrgScope = function(orgScopeStr,adminId){
		return $http({
			method : "post",
			url : "../workbench/orgscope/addAdminOrgScope.json",
			data : $.param({"orgScopeStr":encodeURI(orgScopeStr),"adminId":adminId}),
			headers:{'Content-Type': 'application/x-www-form-urlencoded'}
		});
	}
	
	//人员调动
	service.moveOrgUser = function(userIds,organizationId){
		return $http({
			method : "post",
			url : "../workbench/orguser/moveOrgUser.json",
			data : $.param({"userIds":userIds,"organizationId":organizationId}),
			headers:{'Content-Type': 'application/x-www-form-urlencoded'}
		});
	}
	
	//管理员重置密码
	service.resetPassword = function(accountId){
		return $http.get("../workbench/orguser/resetPassword.json?accountId="+accountId);
	}
	
	//调整用户状态
	service.updateGroupManager = function(userId,currentState){
		return $http.get("../workbench/orguser/updateGroupManager.json?orgUserIds=" + userId + "&isGroupManager="+ currentState);
	}
	
	return service;
});
